package com.wzt.lianfirecontrol.adapter.xuncha;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wzt.lianfirecontrol.R;
import com.wzt.lianfirecontrol.adapter.BaseRecyclerAdapter;
import com.wzt.lianfirecontrol.bean.recode.function.xuncha.XunChaFloorModel;
import com.wzt.lianfirecontrol.utils.Utils;

public class XunChaFloorAdapter extends BaseRecyclerAdapter<XunChaFloorModel> {

    private Context context;

    private boolean isHistory = false;

    public boolean isHistory() {
        return isHistory;
    }

    public void setHistory(boolean history) {
        isHistory = history;
    }

    public XunChaFloorAdapter(Context context) {
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_xuncha_floorlist, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int RealPosition, XunChaFloorModel data) {
        if (viewHolder instanceof MyViewHolder){
            setItemData((MyViewHolder)viewHolder, data, RealPosition);
        }
    }

    private class MyViewHolder extends RecyclerView.ViewHolder {
        private LinearLayout ll_item_content;
        private TextView tv_floor;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            initItemView(this, itemView);
        }
    }

    private void initItemView(MyViewHolder myViewHolder, View itemView) {
        myViewHolder.ll_item_content = itemView.findViewById(R.id.ll_item_content);
        myViewHolder.tv_floor = itemView.findViewById(R.id.tv_floor);
    }

    private void setItemData(MyViewHolder viewHolder, XunChaFloorModel data, int postion) {
        viewHolder.ll_item_content.setPadding(Utils.dip2px(context, 5f), Utils.dip2px(context, 6), Utils.dip2px(context, 5f), Utils.dip2px(context, 6));
        viewHolder.tv_floor.setText(data.getFloorName());
        if (isHistory){
            viewHolder.tv_floor.setBackground(context.getResources().getDrawable(R.drawable.shape_white_bg_frame));
        }
    }
}
